﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfBinding
{
    /// <summary>
    /// BasicBindings.xaml 的交互逻辑
    /// </summary>
    public partial class BasicBindings : Page
    {
        public BasicBindings()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Binding binding = new Binding();
            binding.Source = comboBox1;
            binding.Path = new PropertyPath("SelectedItem.Content");
            binding.StringFormat = "Content:{0}";
            textBlock2.SetBinding(TextBlock.TextProperty, binding);
    
            BindingOperations.SetBinding(textBlock3, TextBlock.TextProperty, binding);

 
        }

        private void btnMove_Click(object sender, RoutedEventArgs e)
        {
            textBlock2.Text = "Remove Binding";

            BindingOperations.ClearBinding(textBlock3, TextBlock.TextProperty);
            //BindingOperations.ClearAllBindings(textBlock3);
        }
    }
}
